package com.ruoyi.common.core.domain.entity;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.utils.StringUtils;
import org.apache.commons.collections.MapUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @UserInfoDetail:
 * @author: Yayo
 * @date: 2021/5/9 21:28
 */
public class UserInfoDetail extends BaseEntity {

    private static final long serialVersionUID = -1287501332388469765L;
    private Long id;
    private Long userId;
    private String registeredAddress;
    private String registeredAddressDetail;
    private String address;
    private String addressDetail;
    private Integer height;
    private Integer weight;
    private String idCard;
    private Map<String,String> addressMap = new HashMap<>();

    public Map<String, String> getAddressMap() {
        return addressMap;
    }

    public void setAddressMap(Map<String, String> addressMap) {
        this.addressMap = addressMap;
        if(MapUtils.isNotEmpty(addressMap)){
            String province = addressMap.get("registerAddressProvince");
            String city = addressMap.get("registerAddressCity");
            String area = addressMap.get("registerAddressArea");
            Map<String,String> register = new HashMap<>();
            register.put("registerAddressProvince",province);
            register.put("registerAddressCity",city);
            register.put("registerAddressArea",area);
            this.registeredAddress = JSONObject.toJSONString(register);

            province = addressMap.get("addressProvince");
            city = addressMap.get("addressCity");
            area = addressMap.get("addressArea");
            Map<String,String> address = new HashMap<>();
            address.put("addressProvince",province);
            address.put("addressCity",city);
            address.put("addressArea",area);
            this.address = JSONObject.toJSONString(address);
        }
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getRegisteredAddress() {
        return registeredAddress;
    }

    public void setRegisteredAddress(String registeredAddress) {
        this.registeredAddress = registeredAddress;
        if(StringUtils.isNotBlank(registeredAddress)){
            Map<String, String> address = JSONObject.parseObject(registeredAddress, Map.class);
            this.addressMap.putAll(address);
        }
    }

    public String getRegisteredAddressDetail() {
        return registeredAddressDetail;
    }

    public void setRegisteredAddressDetail(String registeredAddressDetail) {
        this.registeredAddressDetail = registeredAddressDetail;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
        if(StringUtils.isNotBlank(address)){
            this.addressMap.putAll(JSONObject.parseObject(address, Map.class));
        }
    }

    public String getAddressDetail() {
        return addressDetail;
    }

    public void setAddressDetail(String addressDetail) {
        this.addressDetail = addressDetail;
    }

    public Integer getHeight() {
        return height;
    }

    public void setHeight(Integer height) {
        this.height = height;
    }

    public Integer getWeight() {
        return weight;
    }

    public void setWeight(Integer weight) {
        this.weight = weight;
    }

    public String getIdCard() {
        return idCard;
    }

    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }
}
